package com.shengyuan.manage_os.old.ying.erpm;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.CurrentPersonal;
import com.shengyuan.manage_os.old.ying.erpm.db.Actual_Data_Table;
import com.shengyuan.manage_os.old.ying.erpm.db.Actual_ErpUser;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;

import java.util.ArrayList;

public class Actual_OA_JiDongRenDengJi extends PreferenceActivity {

	SharedPreferences  sp;
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.jidongrenyuan);
//		Actual_ErpUser erpUser = new Actual_ErpUser(this);
//		ArrayList<String> arrayList = erpUser.getAllUserName();
//
//		if (arrayList.size() > 0) {
//			CharSequence[] entries = new CharSequence[arrayList.size()] ;
//			for (int i = 0; i < entries.length; i++) {
//				entries[i] = arrayList.get(i);
//			}
//			ListPreference lp = (ListPreference)findPreference("shangbandengji_selectren");
//			lp.setEntries(entries);
//			lp.setEntryValues(entries);
//
//		}

		sp = PreferenceManager.getDefaultSharedPreferences(this); 
		sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){   
			  
			@Override  
			//sharedPreferences:句柄   
			//key: 改变 键值   
			public void onSharedPreferenceChanged(   
			SharedPreferences sharedPreferences, String key) {   
			// TODO Auto-generated method stub   
			  
			if(key.equals("shangbandengji_selectren")){   
			String autoBack = sharedPreferences.getString("shangbandengji_selectren", "");   
			}
			}});  

	}

	@Override
	@Deprecated
	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
			Preference preference) {
		if(LoginActivity.pmUser.ID == 0){
			Utility.MessageBox(this,"您的登录出现异常，请重新登录");
			return false;
		}
		if (preference.getKey().equals("DengJiTime1") || preference.getKey().equals("DengJiTime2")) {
//			SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
//			String value = sharedPreferences.getString("shangbandengji_selectren", LoginActivity.pmUser.UserName);
			Actual_Data_Table dbo = new Actual_Data_Table(Actual_OA_JiDongRenDengJi.this);
			int i  = dbo.get_Sended_DaKa();

			dbo.close();
			if (i ==2 && preference.getKey().equals("DengJiTime2")) {
				Utility.MessageBox(this,"已经记录了下班打卡");
			}else {
				String key = preference.getKey();
				if (i==0) {
					Utility.MessageBox(this, LoginActivity.pmUser.UserName + " 在本机第一次打卡!");
				}else if((i==3 || i==1)  && preference.getKey().equals("DengJiTime1"))  {
					Utility.MessageBox(this,"已经在上班中，你要补打记录！");
					key ="补打定位";
				}
				CurrentPersonal.UserName = LoginActivity.pmUser.UserName;
				Intent intent = new Intent( this, Actual_OA_DaKa_JiDong.class);
				intent.putExtra("DengJi", key);
				this.startActivity(intent);				
			}

		}else if(preference.getKey().equals("shangbandengji_selectren")) {
			
		}
		return super.onPreferenceTreeClick(preferenceScreen, preference);
		
	}

	

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

}
